package com.settlement.system.service.impl;

import com.settlement.system.model.entity.WmNoRecord;
import com.settlement.system.mapper.WmNoRecordMapper;
import com.settlement.system.service.WmNoRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.util.Assert;
import com.settlement.system.common.util.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.model.query.WmNoRecordQuery;
import com.settlement.system.model.form.WmNoRecordForm;
import org.springframework.beans.BeanUtils;
import com.settlement.system.model.vo.WmNoRecordImportVo;

/**
 * <p>
 * 微盟交易单号表 服务实现类
 * </p>
 *
 * @author huangrensen
 * @since 2024-07-10
 */
@Service
public class WmNoRecordServiceImpl extends ServiceImpl<WmNoRecordMapper, WmNoRecord> implements WmNoRecordService {

    @Override
    public Page<WmNoRecord> getPage(WmNoRecordQuery queryParams) {
        // 查询参数
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        // 查询数据
        Page<WmNoRecord> page = new Page<>(pageNum, pageSize);
        return this.baseMapper.getPage(page, queryParams);
    }

     @Override
     public boolean saveWmNoRecord(WmNoRecordForm wmNoRecordForm) {
         WmNoRecord wmNoRecord = new WmNoRecord();
         BeanUtils.copyProperties(wmNoRecordForm, wmNoRecord);
         return this.saveOrUpdate(wmNoRecord);
     }

     @Override
     public WmNoRecordForm getWmNoRecordFormData(Long id) {
         WmNoRecord wmNoRecord = this.getById(id);
         WmNoRecordForm wmNoRecordForm = new WmNoRecordForm();
         BeanUtils.copyProperties(wmNoRecord, wmNoRecordForm);
         return wmNoRecordForm;
     }

     @Override
     public boolean deleteWmNoRecord(String ids) {
        Assert.isTrue(StringUtils.hasText(ids), "删除的数据为空");
        List<Long> idArray = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
        return this.removeByIds(idArray);
     }

    @Override
    public void importData(List<WmNoRecordImportVo> voList)  {
        List<WmNoRecord> wmNoRecordList = new ArrayList<>();
        for (WmNoRecordImportVo importVo : voList) {
            WmNoRecord wmNoRecord = new WmNoRecord();
            BeanUtils.copyProperties(importVo, wmNoRecord);
            wmNoRecordList.add(wmNoRecord);
        }
        this.saveOrUpdateBatch(wmNoRecordList);
    }

    @Override
    public List<WmNoRecordImportVo> findByIds(String idsStr) {
        if (!StringUtils.hasText(idsStr)) {
            return new ArrayList<>();
        }
        List<Long> ids = Arrays.stream(idsStr.split(",")).map(Long::parseLong).collect(Collectors.toList());
        List<WmNoRecord> wmNoRecordList = this.getBaseMapper().selectBatchIds(ids);
        List<WmNoRecordImportVo> voList = new ArrayList<>();
        for (WmNoRecord wmNoRecord : wmNoRecordList) {
            WmNoRecordImportVo vo = new WmNoRecordImportVo();
            BeanUtils.copyProperties(wmNoRecord, vo);
            voList.add(vo);
        }
        return voList;
    }
}
